//index.js

var weatherUtil=require('../../utils/weatherApi.js');
var amapFile = require('../../utils/amap-wx.js');
var config = require('../../utils/config.js');

var app = getApp();

function refreshData(that){
  weatherUtil.loadWeatherData((success,data)=>{
    that.setData({
      weather:data
    });
    wx.stopPullDownRefresh();
  });
}

Page({
  data: {
    backgroundUrl: 'http://wechat-1252404746.cossh.myqcloud.com/backgroundimg.jpeg',
    weather:{},
    textData:'',
    latitude:'',
    longitude:''
  },
  onLoad:function(){
    var that=this;
    refreshData(that);
    var key=config.Config.key;
    var myAmapFun = new amapFile.AMapWX({key:key});

    myAmapFun.getRegeo({
      success:function(data){
        //成功回调
        var marker=[{
          latitude:data[0].latitude,
          longitude:data[0].longitude,
          
        }]
        that.setData({
          latitude:data[0].latitude
        });
        that.setData({
          longitude:data[0].longitude
        });
        that.setData({
          textData:data[0].desc
        })
      },
      fail:function(data){
        console.log(info)
      }
    })
  }
})
